package com.sino.operation.service.business;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sino.operation.commons.ConstantValue;
import com.sino.operation.commons.commonEnum.VoucherType;
import com.sino.operation.commons.util.Exec_Util;
import com.sino.operation.entity.BizDespositInfo;
import com.sino.operation.entity.BizExchangeInfo;

import java.util.Map;

/**
 * @Title: Exec_710306_Util
 * @Description:
 * @Author dengls
 * @date 2021/11/2 16:02
 */
public class Exec_710306_Util {
    //将中心录入字段进行登记薄归集
    public static BizDespositInfo CollectionHandle(Map<String, Map> data, BizDespositInfo despositInfo) {
        //定期(通知)存款、单位协议存款、同业存放定期存款、同业存放通知存款
        String zczh = data.containsKey("ZCZH") ? data.get("ZCZH").containsKey("value") ? data.get("ZCZH").get("value").toString() : "" : ""; //转出账号
        String zczhhm = data.containsKey("ZCZHHM") ? data.get("ZCZHHM").containsKey("value") ? data.get("ZCZHHM").get("value").toString() : "" : "";//转出账户户名
        String fkrkhh = data.containsKey("FKRKHH") ? data.get("FKRKHH").containsKey("value") ? data.get("FKRKHH").get("value").toString() : "" : "";//付款人开户行名
        String zcpzhm = data.containsKey("ZCPZHM") ? data.get("ZCPZHM").containsKey("value") ? data.get("ZCPZHM").get("value").toString() : "" : "";//转出凭证号码
        String khje = data.containsKey("KHJE") ? data.get("KHJE").containsKey("value") ? data.get("KHJE").get("value").toString() : "" : "";//开户金额(交易金额)
        String cprq = data.containsKey("CPRQ") ? data.get("CPRQ").containsKey("value") ? data.get("CPRQ").get("value").toString() : "" : "";//出票日期
        String zfmm = data.containsKey("ZFMM") ? data.get("ZFMM").containsKey("value") ? data.get("ZFMM").get("value").toString() : "" : "";//支付密码
        String cq = data.containsKey("CQ") ? data.get("CQ").containsKey("value") ? data.get("CQ").get("value").toString() : "" : "";//存期
        String qxr = data.containsKey("QXR") ? data.get("QXR").containsKey("value") ? data.get("QXR").get("value").toString() : "" : "";//起息日（默认返显当天）
        String dxr = data.containsKey("DXR") ? data.get("DXR").containsKey("value") ? data.get("DXR").get("value").toString() : "" : "";//到期日（根据存期返显）
        String fxpl = data.containsKey("FXPL") ? data.get("FXPL").containsKey("value") ? data.get("FXPL").get("value").toString() : "" : "";//付息频率
        String sfglhqyjk = data.containsKey("SFGLHQYJK") ? data.get("SFGLHQYJK").containsKey("value") ? data.get("SFGLHQYJK").get("value").toString() : "" : "";//是否关联活期印鉴卡
        String hqdgzh = data.containsKey("HQDGZH") ? data.get("HQDGZH").containsKey("value") ? data.get("HQDGZH").get("value").toString() : "" : "";//活期对公账号
        String zcfs = data.containsKey("ZCFS") ? data.get("ZCFS").containsKey("value") ? data.get("ZCFS").get("value").toString() : "" : "";//转存方式
        String zccq = data.containsKey("ZCCQ") ? data.get("ZCCQ").containsKey("value") ? data.get("ZCCQ").get("value").toString() : "" : "";//转存存期
        String product_type = data.containsKey("PRODUCT_TYPE") ? data.get("PRODUCT_TYPE").containsKey("value") ? data.get("PRODUCT_TYPE").get("value").toString() : "" : "";//产品类型
        despositInfo.setPayAcc(zczh);
        despositInfo.setPayName(zczhhm);
        despositInfo.setPayBname(fkrkhh);
        despositInfo.setZccerno2(zcpzhm);
        despositInfo.setAmount(khje);
        despositInfo.setCerdate(cprq);
        despositInfo.setPaypwd(zfmm);
        despositInfo.setCq(cq);
        despositInfo.setQxr(qxr);
        despositInfo.setDxr(dxr);
        despositInfo.setFxpl(fxpl);
        despositInfo.setSfglhqyjk(sfglhqyjk);
        despositInfo.setHqdgzh(hqdgzh);
        despositInfo.setZcfs(zcfs);
        despositInfo.setBondterm(zccq);
        if (ConstantValue.DWTZCK.equals(product_type) || ConstantValue.DWDQCK.equals(product_type)) {
            //定期存款、通知存款
            String skrmc = data.containsKey("SKRMC") ? data.get("SKRMC").containsKey("value") ? data.get("SKRMC").get("value").toString() : "" : "";//收款人名称
            String skrkhhmc = data.containsKey("SKRKHHMC") ? data.get("SKRKHHMC").containsKey("value") ? data.get("SKRKHHMC").get("value").toString() : "" : "";//收款人开户行名称
            String zdzcfs = data.containsKey("ZDZCFS") ? data.get("ZDZCFS").containsKey("value") ? data.get("ZDZCFS").get("value").toString() : "" : "";//自动转存标志
            String zdzczh = data.containsKey("ZDZCZH") ? data.get("ZDZCZH").containsKey("value") ? data.get("ZDZCZH").get("value").toString() : "" : "";//自动转存账户
            String zxll = data.containsKey("ZXLL") ? data.get("ZXLL").containsKey("value") ? data.get("ZXLL").get("value").toString() : "" : "";//执行利率
            despositInfo.setRecvName(skrmc);
            despositInfo.setRecvBName(skrkhhmc);
            despositInfo.setZdzcbz(zdzcfs);
            despositInfo.setZdzczh(zdzczh);
            despositInfo.setZxll(zxll);
        }
        if (ConstantValue.DWXYCK.equals(product_type)) {
            //单位协议存款
        }
        if (ConstantValue.TYCFDQ.equals(product_type) || ConstantValue.TYCFTZ.equals(product_type)) {
            //同业存放定期存款、同业存放通知存款
            String skrmc = data.containsKey("SKRMC") ? data.get("SKRMC").containsKey("value") ? data.get("SKRMC").get("value").toString() : "" : "";//收款人名称
            String skrkhhmc = data.containsKey("SKRKHHMC") ? data.get("SKRKHHMC").containsKey("value") ? data.get("SKRKHHMC").get("value").toString() : "" : "";//收款人开户行名称
            String ckjgdfrjg = data.containsKey("CKJGDFRJG") ? data.get("CKJGDFRJG").containsKey("value") ? data.get("CKJGDFRJG").get("value").toString() : "" : "";//存款机构的法人机构
            despositInfo.setRecvName(skrmc);
            despositInfo.setRecvBName(skrkhhmc);
            despositInfo.setCkjgdfrjg(ckjgdfrjg);
        }
        return despositInfo;
    }

    //判重
    public static QueryWrapper<BizDespositInfo> repeatJudge(BizDespositInfo bizDespositInfo) {
        QueryWrapper<BizDespositInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("JOURNAL_NO", bizDespositInfo.getJournalNo() == null ? "" : bizDespositInfo.getJournalNo());
        wrapper.eq("AMOUNT", Exec_Util.addPoint(bizDespositInfo.getAmount()) == null ? "" : Exec_Util.addPoint(bizDespositInfo.getAmount()));
        wrapper.eq("TRANS_DATE", bizDespositInfo.getTransDate() == null ? "" : bizDespositInfo.getTransDate());
        wrapper.eq("PAY_ACC", bizDespositInfo.getPayAcc() == null ? "" : bizDespositInfo.getPayAcc());
        wrapper.eq("RECV_BNAME", bizDespositInfo.getRecvBName() == null ? "" : bizDespositInfo.getRecvBName());
        wrapper.eq("PAY_BNAME", bizDespositInfo.getPayBname() == null ? "" : bizDespositInfo.getPayBname());
        wrapper.eq("TRANS_CODE", bizDespositInfo.getTransCode() == null ? "" : bizDespositInfo.getTransCode());
        wrapper.eq("ORGAN_ID", bizDespositInfo.getOrganId() == null ? "" : bizDespositInfo.getOrganId());
        wrapper.eq("SOURCE", bizDespositInfo.getSource() == null ? "" : bizDespositInfo.getSource());
        String voucherType = bizDespositInfo.getZcpzlx();
        //如果凭证种类是支票 或者 电汇 获取凭证号码作为判重依据
        if (VoucherType.VOUCHERTYPE01.getValue().equals(voucherType) || VoucherType.VOUCHERTYPE38.getValue().equals(voucherType)) {
            wrapper.eq("CERTY", bizDespositInfo.getZcpzlx() == null ? "" : bizDespositInfo.getZcpzlx().length() > 16 ?
                    bizDespositInfo.getZcpzlx().substring(0, 16) : bizDespositInfo.getZcpzlx());
        }
        return wrapper;
    }
}
